package tcp;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

public class Client {
    public static void main(String[] args) throws  Exception{
        //1.创建Scoket对象，指定ip和端口
        Socket socket = new Socket("localhost", 9999);
        //2.获取传输数据的对象流
        OutputStream outputStream = socket.getOutputStream();
        InputStream inputStream = socket.getInputStream();
        //3.传输数据
        outputStream.write("你好啊".getBytes());

        byte[] bytes = new byte[1024];
        int len = inputStream.read(bytes);
        System.out.println(new String(bytes,0,len));

        //4.释放资源
        socket.close();

    }
}
